import 'package:enterprise_v6_app/app/components/custom_refresh.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/Inventory_system/get_the_feign_emergency_plans_page_entity.dart';

///应急预案清单
class EmergencyPlanListController extends GetxController {
  /// 筛选右侧栏控制Key
  final riskRightScaffoldKey = GlobalKey<ScaffoldState>();

  /// 列表刷新key
  final GlobalKey<CustomEasyRefreshListState> globalKey = GlobalKey();

  /// 预案类别
  String planType = '';
  String searchPlanType = '';

  /// 预案名称
  String searchSelect = '';
  RxString searchX = ''.obs;

  /// 获取数据
  Future<List<GetTheFeignEmergencyPlansPageEntity>> theFeignEmergencyPlansPage(int index, int size, {String? search}) async {
    final res = await HttpUtil().generateGetRequest<List<GetTheFeignEmergencyPlansPageEntity>>(
      Interface.getTheFeignEmergencyPlansPage,
      queryParameters: {
        'pageNum': index,
        'pageSize': size,
        'emergencyPlanName':  searchX.value, // 预案名称
        'planType': planType, //	预案类别
      },
    ).execute();
    List<GetTheFeignEmergencyPlansPageEntity>? list = [];
    res.onSuccess((result) {
      if (result.data != null) {
        list = result.data;
      }
    });
    return list!;
  }

  /// 筛选按钮
  void onFilterButtonPressed() {
    searchSelect = searchX.value; //向另一个地方插入值 那个地方也和这一样
    riskRightScaffoldKey.currentState?.openEndDrawer();
  }

  /// 重置
  void reset() {
    searchX.value = '';
    searchSelect = '';
    searchPlanType = '';
    planType = '';
    riskRightScaffoldKey.currentState?.closeEndDrawer();
    // selectedEntity = RiskTreeEntity();
    globalKey.currentState!.onRefresh();
    update();
  }

  /// 确定
  void confirm() {
    Get.back();
    searchX.value = searchSelect;
    planType = searchPlanType;
    globalKey.currentState!.onRefresh();
    update();
  }

  void refreshPage() {
    globalKey.currentState?.onRefresh();
  }
}
